/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package util;

import java.sql.Connection;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

/**
 *
 * @author duonghung1369
 */
public class ConnectDB implements IdbUtil {
    @Override
    public  Connection getConnection(){
        try{
            InitialContext ctx = new InitialContext();
            Context envCtx = (Context) ctx.lookup("java:comp/env");
            DataSource ds = (DataSource) envCtx.lookup("DBCon");
            return ds.getConnection();
        }catch(Exception ex){
            ex.printStackTrace();
            return null;
        }
    }

    @Override
    public void closeConnection() {
        throw new UnsupportedOperationException("Not supported yet.");
    }


}
